# delimit ;
clear ;
cd "replication" ;
set more off ; 

* *************************************************************************** ;
* re-run endline analysis
* *************************************************************************** ;

cd ".." ;
do "./replication/do/table05-endline-behavior.do" ; 

* ***************************************************************************** ;
* relabel variables to make them fit in the LaTeX table in portait layout
* ***************************************************************************** ;

* label variables for the tables ;
label var behav_all "\shortstack[l]{Total\\no. of\\beha-\\viors\\adopted}" ;
label var water_boil_filter "\shortstack[l]{Drinks\\filtered\\or\\boiled\\water}" ;
label var water_tap "\shortstack[l]{Uses\\a water\\vessel\\with tap}" ;
label var wash_soap3 "\shortstack[l]{Washes\\hands\\with\\soap\\at least\\thrice\\daily}" ;
label var pregnancy_anc "\shortstack[l]{Would\\go for\\ante-\\natal\\care if\\self/\\spouse\\pregnant}" ;
label var pregnancy_hospital "\shortstack[l]{Would\\go for\\hospital\\delivery\\if\\self/\\spouse\\pregnant}" ; 
label var aids_tested_self "\shortstack[l]{Has been\\tested\\for HIV\\in the\\last 3\\months}" ; 
label var condom_use "\shortstack[l]{Uses\\condom\\during\\inter-\\course}" ; 
label var nightblindness_food "\shortstack[l]{Eats\\more\\nutritious\\foods to\\prevent\\night-\\blindness}" ;

* ***************************************************************************** ;
* regressions, robustness check 1: Removing strata fixed effects
* ***************************************************************************** ;

foreach var in behav_all $module1_behav $module23_behav $module4_behav $module5_behav  { ;
	
	reg `var' healthonly healthandpay, robust ;
	qui est sto `var'1; 
	
	test healthonly = healthandpay ; 
	estadd local titlerow = "" ; 
	estadd scalar fstat = r(F): `var'1 ; 
	estadd scalar pval = r(p): `var'1 ; 

	summarize `var' if control == 1 & e(sample) == 1;
	estadd scalar cmean = r(mean): `var'1 ; 
	estadd scalar csd = r(sd): `var'1 ;

} ;

* ***************************************************************************** ;
* regressions, robustness check 2: clustered standard errors
* ***************************************************************************** ;

foreach var in behav_all $module1_behav $module23_behav $module4_behav $module5_behav  { ;
	
	areg `var' healthonly healthandpay, a(strata) robust cluster(waveclass) ;
	qui est sto `var'2 ; 
	
	test healthonly = healthandpay ; 
	estadd local titlerow = "" ; 
	estadd scalar fstat = r(F): `var'2 ; 
	estadd scalar pval = r(p): `var'2 ; 

	summarize `var' if control == 1 & e(sample) == 1;
	estadd scalar cmean = r(mean): `var'2 ; 
	estadd scalar csd = r(sd): `var'2 ;

} ;

* **************************************************************************
* output results from robustness check 1
* ************************************************************************** ;

esttab behav_all*1 water*1 wash*1 pregnancy*1 aids*1 condom*1 night*1 using "./output/appendix-table-alternative-specifications-endline-behavior-panelA.tex",
	replace
	drop(_cons) 
	cells(b(label() star fmt(%9.3f %9.3f)) se(par)) 
	star(* 0.10 ** 0.05 *** 0.01) 
	stats(titlerow fstat pval cmean csd N, fmt(%9s %9.3f %9.3f %9.3f %9.3f %9.0f) labels("\(F\)-test, HEE = HEEC" "$\qquad$ \(F\)-statistic" "$\qquad$ \(p\)-value" "Control Mean" "Control SD" "N"))
	prehead(\begin{table}[htbp] \centering \normalsize `"\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"'
		\captionsetup{justification=centering} 
		\caption{Effects on Health Behaviors \\ Alternative Regression Specifications}
		\footnotesize
		\label{appendix-table-alternative-reg-spec-endline-behavior}
		\begin{tabular*}{\hsize}{p{2.9cm}p{1cm}p{1cm}p{1cm}p{1cm}p{1cm}p{1cm}p{1cm}p{1cm}p{1cm}}
		\toprule)
	legend label  booktabs  collabels( , none)
	mgroups(
	"All Topics" 
	"\shortstack[c]{Cleanliness\\and Hygiene}"
	"\shortstack[c]{Midwives,\\Maternal \& Child\\Health}"
	"\shortstack[c]{Condoms, AIDS,\\Syphilis}" 
	"\shortstack[c]{Night-\\blindness}"
	, pattern(1 1 0 0 1 0 1 0 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
	posthead(\midrule \end{tabular*}
	\bigskip
	\captionsetup[sub]{justification=raggedleft} 
	\subcaption*{Panel A: Removing Strata Fixed Effects} 
	\vspace{-0.5ex}
	\newcolumntype{C}{>{\centering\arraybackslash}X}
	\begin{tabularx}{\linewidth}{lCCCCCCCCC} 
	\midrule
	&\multicolumn{1}{c}{(1)} &\multicolumn{1}{c}{(2)} &\multicolumn{1}{c}{(3)}
	&\multicolumn{1}{c}{(4)} &\multicolumn{1}{c}{(5)} &\multicolumn{1}{c}{(6)}
	&\multicolumn{1}{c}{(7)} &\multicolumn{1}{c}{(8)} &\multicolumn{1}{c}{(8)}
	\\ \midrule)
	postfoot(`"\midrule"'  \end{tabularx}) ;

* **************************************************************************
*  output results from robustness check 2
* ************************************************************************** ;
	
esttab behav_all*2 water*2 wash*2 pregnancy*2 aids*2 condom*2 night*2 using "./output/appendix-table-alternative-specifications-endline-behavior-panelB.tex",
	replace nodepvars nomtitles
	drop(_cons)
	eqlabels(none)
	cells(b(label() star fmt(%9.3f %9.3f)) se(par)) 
	star(* 0.10 ** 0.05 *** 0.01) 
	stats(titlerow fstat pval cmean csd N, fmt(%9s %9.3f %9.3f %9.3f %9.3f %9.0f) labels("\(F\)-test, HEE = HEEC" "$\qquad$ \(F\)-statistic" "$\qquad$ \(p\)-value" "Control Mean" "Control SD" "N"))
	prehead(\bigskip
	\subcaption*{Panel B: Clustered Standard Errors }
	\vspace{-0.5ex}
	\setlength{\tabcolsep}{6pt}
	\begin{tabularx}{\linewidth}{lCCCCCCCCC}
	\midrule)
	label booktabs collabels( , none)
	postfoot(`"\midrule"'  \end{tabularx}
	\captionsetup{justification=justified, width=\linewidth} 
	\caption*{\footnotesize \textit{Notes:} This table examines the robustness of the results presented in Table \ref{table-endline-behavior} to different regression specifications. Panel A excludes randomization strata fixed effects from the regression. Panel B uses standard errors clustered at the wave-class level.
	***\$\,p < 0.01$, **\$\,p < 0.05$, *\$\,p<0.10$.
		}
	\end{table}) ;

exit ;

